﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KVB.Common;
using Customer_Profile.eCard.DBDao;
using Customer_Profile.Admin;

namespace Customer_Profile.eCard.Match
{
    public partial class netBankSearch : System.Web.UI.Page
    {
        string strUserName = "";
        string strUserID = "";
        string strEntity = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Comm.CheckSession(this.Page, "/login.aspx", "usermodel");
            if (Session["usermodel"] != null)
            {
                strUserID = ((UserInfoEntity)Session["usermodel"]).UserLoginId;
                strUserName = ((UserInfoEntity)Session["usermodel"]).UserName;
                strEntity = ((UserInfoEntity)Session["usermodel"]).UserOffice;
            }
            else
            {
                Log.WriteDefaultLog("main_01 Page_Load", "Session is null");
                return;
            }
            string strURL = HttpContext.Current.Request.Url.AbsolutePath;
            bool bok = Comm.ifhasright(strUserID, strURL);
            if (!bok)
            {
                Response.Write("你无权访问此页面");
                Response.End();
            }

            if (!Page.IsPostBack)
            {
                Comm.BindDll(ref dropBankName, "netbank_name", false, "");
                txtcreatedatebegin.Text = DateTime.Now.ToString("yyyy-MM-dd");
                txtcreatedateend.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }

            bindGrid();
        }

        private void bindGrid()
        {
            try
            {
                string start_date = txtcreatedatebegin.Text.Trim();
                string end_date = txtcreatedateend.Text.Trim();
                DataSet ds = netBankDao.getnetbankInfo_byBankname(dropBankName.SelectedItem.Text, start_date, end_date);
                gridReward.DataSource = ds;
                gridReward.DataBind();                
                gridReward.EnableCallBacks = false;
            }
            catch (Exception ex)
            {
                KVB.Common.Log.WriteDefaultLog("netBankSearch.bindGrid", ex.ToString());
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

        }

        protected void gridReward_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
        {
            try
            {
                if (e.ButtonID != "Delete") return;
                int seq_no = int.Parse(gridReward.GetRowValues(e.VisibleIndex, "seq_no").ToString());
                string status = "";
                string message = "";
                netBankDao.deleteNetbankbySeqNo(seq_no,out status,out message);
                if (status.Equals("Y"))
                {
                    bindGrid();
                    lblWarning.Text = "删除成功！";
                }
                else
                {
                    lblWarning.Text = message;                    
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }
}